package com.niit.covid.topN;

import com.niit.covid.bean.CovidBean;
import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

/**
 * mapReduce中自定义分组的类
 */
public class CovidGroupingComparator extends WritableComparator {


    //无参构造器
    protected CovidGroupingComparator(){
        //允许创建对象的实例
        super(CovidBean.class,true);
    }

    @Override
    public int compare(WritableComparable a, WritableComparable b) {
        //多态，，，，强制类型转换
        CovidBean aBean = (CovidBean) a;
        CovidBean bBean = (CovidBean) b;

        //只要前后两个数据的state一样，就应该分到一组
        //只要compare返回0，
        return  aBean.getState().compareTo(bBean.getState());
    }
}
